<?php

class AjaxController extends Controller{
	
	
	public function __construct() {
		parent::__construct();
	}
	
	public function dancers(){
		$dancer1 = $this->_getRandomFile("img/dancers/left");
		$dancer2 = $this->_getRandomFile("img/dancers/right");
		
		echo "['$dancer1','$dancer2']";
	}
	
	private function _getRandomFile($path) {
		$dir = @opendir($path);
		if($dir) {
			$files = array();
			while ($f = readdir($dir)) {
				if(!preg_match('/^\./',$f)) {
					$files[] = $f;
				}
			}
			
			if(count($files)) {
				$max = count($files);
				$file = $files[rand(0,$max-1)];
				return "/".preg_replace("/\/+$/","",$path)."/".$file;
			}else{
				header("HTTP/1.1 400 No file found.");
			}
		}else{
			header("HTTP/1.1 500 Error opening DIR $path.");
		}
	}
}

?>